package com.ellecity06.cwhiskymall.ui.mine.contact

import android.os.Bundle
import android.view.View
import com.ellecity06.common.base.BaseMvvmActivity
import com.ellecity06.common.base.BaseViewModel
import com.ellecity06.common.ktx.requestStorePermission
import com.ellecity06.common.utils.BitmapUtils
import com.ellecity06.common.utils.FileUtil
import com.ellecity06.common.utils.ToastUtils
import com.ellecity06.cwhiskymall.databinding.ActivityContactUsBinding
import com.ellecity06.cwhiskymall.ui.webview.WebHelper

/**
 * @author ellecity06
 * @time 2024/11/2 18:13
 * @des 联系我们
 */
class ContactUsActivity : BaseMvvmActivity<ActivityContactUsBinding, BaseViewModel>(),
    View.OnClickListener {
    override fun inflateBinding(): ActivityContactUsBinding {
        return ActivityContactUsBinding.inflate(layoutInflater)
    }

    override fun initialize(savedInstanceState: Bundle?) {
        title = "联系我们"
        binding.tvContactCustomer.setOnClickListener(this)
        binding.tvSaveImage.setOnClickListener(this)
    }

    override fun onClick(view: View?) {
        when (view?.id) {
            binding.tvContactCustomer.id -> {
                WebHelper.toKefu(this)
            }
            binding.tvSaveImage.id -> {
                try {
                    val bitmapFromView = BitmapUtils.createBitmapFromView(binding.ivPoster)
                 requestStorePermission(desc = "保存分享图需要您授予文件权限") { allGranted, grantedList, deniedList ->
                        if (allGranted) {
                            FileUtil.saveImageFileToExternal(
                                this,
                                imageName = FileUtil.getRandomImageName(),
                                imageBitmap = bitmapFromView
                            )
                            ToastUtils.show("保存成功")
                        }
                    }

                } catch (e: Exception) {
                    ToastUtils.show("保存失败")
                }
            }
        }
    }
}